{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Automatically created module for IPython interactive environment\n",
      "Coefficients: \n",
      " [ 938.23786125]\n",
      "Mean squared error: 2548.07\n",
      "Variance score: 0.47\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAWQAAADuCAYAAAAOR30qAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAEGNJREFUeJzt3W2MXFUdx/HfnT7oDtBaKKixzL1I\nrNQiCKzVaFR8wuc3BjVxrDE+TAyBEEmokUk0mgyx+goIPgw1xrD3jUo0EWNSaiXGRKNbIbEIJURm\ntmgwbQXbZrr0Ya4vjrPTdnfm3tvunXvuud9Psi86nG3+m4Vf/vzPued6URQJAJC/St4FAAAMAhkA\nLEEgA4AlCGQAsASBDACWIJABwBIEMgBYgkAGAEsQyABgiZVpFq9fvz4KgiCjUgDATXv27DkYRdGl\ncetSBXIQBJqdnT33qgCghDzP6yZZx8gCACxBIAOAJQhkALAEgQwAliCQAcASBDIAp4VhqCAIVKlU\nFASBwjDMu6SRUh17A4AiCcNQjUZDvV5PktTtdtVoNCRJ9Xo9z9KWRIcMwFnNZnMhjAd6vZ6azWZO\nFY1HIANw1tzcXKrP80YgA3BWrVZL9XneCGQAzmq1WqpWq2d8Vq1W1Wq1cqpoPAIZgLPq9bra7bZ8\n35fnefJ9X+1228oNPUnyoihKvHh6ejriciEASMfzvD1RFE3HraNDBgBLEMgAYAkCGQAsQSADgCUI\nZACwBIEMAJYgkAHAEgQyAFiCQAYASxDIAGAJAhkALEEgA4AlCGQAsASBDACWIJABwBIEMgBYgkAG\nAEsQyABgCQIZACxBIAOAJQhkALAEgQwAliC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0gczdwsXF\n7B+uKm0gu3K3cNnCaTD773a7iqJoYfbv+s+NkoiiKPHXDTfcELlkZmYm8n0/8jwv8n0/mpmZybuk\nVGZmZqJqtRpJWviqVqtjf46i/8y+75/x8w6+fN/PuzRgJEmzUYKMtfq2N4wXBIG63e6iz33fV6fT\nWfT52SdLJPN/BUW67rNSqWipf2c9z1O/38+hIiBe0tveSjuycEHajUkXTpYw+4fLCOQCSxtOLpws\ncWX2DyyFQC6wtOHkQnfJG1bgMgK5wNKGkyvdJe8VhKsKEchlO9qVRppworsE7Gb9KQsXTgYAKDdn\nTlm4cDIAAJKwPpBdOBkAAElYH8gunAwAgCSsD2RXTgYAQByrAzkMw4UZ8ooVKySJkwElwckalJG1\nbww5+3TFqVOnFjpjwthtvM0FZWXtsbe0F+fAHfzu4ZrCH3vjdEV58btHWVkbyJyuKC9+9ygrawOZ\n0xXlxe8eZWVtIHPvQnnxu0dZWbupBwCuKPymHgCUDYEMAJYgkAHAEgQyAFiCQAYAS6Q6ZeF53gFJ\ni59pBQCM40dRdGncolSBDADIDiMLALAEgQwAliCQAcASBDIAWIJABgBLEMgAYAkCGQAsQSADgCUI\nZACwxP8AsWFvuyTpQhMAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x10c788b00>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "print(__doc__)\n",
    "\n",
    "\n",
    "# Code source: Jaques Grobler\n",
    "# License: BSD 3 clause\n",
    "\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "from sklearn import datasets, linear_model\n",
    "from sklearn.metrics import mean_squared_error, r2_score\n",
    "\n",
    "# Load the diabetes dataset\n",
    "diabetes = datasets.load_diabetes()\n",
    "\n",
    "\n",
    "# Use only one feature\n",
    "diabetes_X = diabetes.data[:, np.newaxis, 2]\n",
    "\n",
    "# Split the data into training/testing sets\n",
    "diabetes_X_train = diabetes_X[:-20]\n",
    "diabetes_X_test = diabetes_X[-20:]\n",
    "\n",
    "# Split the targets into training/testing sets\n",
    "diabetes_y_train = diabetes.target[:-20]\n",
    "diabetes_y_test = diabetes.target[-20:]\n",
    "\n",
    "# Create linear regression object\n",
    "regr = linear_model.LinearRegression()\n",
    "\n",
    "# Train the model using the training sets\n",
    "regr.fit(diabetes_X_train, diabetes_y_train)\n",
    "\n",
    "# Make predictions using the testing set\n",
    "diabetes_y_pred = regr.predict(diabetes_X_test)\n",
    "\n",
    "# The coefficients\n",
    "print('Coefficients: \\n', regr.coef_)\n",
    "# The mean squared error\n",
    "print(\"Mean squared error: %.2f\"\n",
    "      % mean_squared_error(diabetes_y_test, diabetes_y_pred))\n",
    "# Explained variance score: 1 is perfect prediction\n",
    "print('Variance score: %.2f' % r2_score(diabetes_y_test, diabetes_y_pred))\n",
    "\n",
    "# Plot outputs\n",
    "plt.scatter(diabetes_X_test, diabetes_y_test,  color='black')\n",
    "plt.plot(diabetes_X_test, diabetes_y_pred, color='blue', linewidth=3)\n",
    "\n",
    "plt.xticks(())\n",
    "plt.yticks(())\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 0.5  0.5] 2.22044604925e-16\n"
     ]
    }
   ],
   "source": [
    "from sklearn import linear_model\n",
    "\n",
    "reg = linear_model.LinearRegression()\n",
    "X = [[0, 0], [1, 1], [2, 2]]\n",
    "y = [0, 1, 2]\n",
    "reg.fit (X, y)\n",
    "\n",
    "print(reg.coef_, reg.intercept_)    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
